﻿<!--*********************************************************************

   Extended WPF Toolkit

   Copyright (C) 2010-2012 Xceed Software Inc.

   This program is provided to you under the terms of the Microsoft Public
   License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license 

   This program can be provided to you by Xceed Software Inc. under a
   proprietary commercial license agreement for use in non-Open Source
   projects. The commercial version of Extended WPF Toolkit also includes
   priority technical support, commercial updates, and many additional 
   useful WPF controls if you license Xceed Business Suite for WPF.

   Visit http://xceed.com and follow @datagrid on Twitter.

  ********************************************************************-->
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:local="clr-namespace:Xceed.Wpf.Toolkit"
                    xmlns:pg="clr-namespace:Xceed.Wpf.Toolkit.PropertyGrid"
                    xmlns:conv="clr-namespace:Xceed.Wpf.Toolkit.Core.Converters"
                    xmlns:pgconv="clr-namespace:Xceed.Wpf.Toolkit.PropertyGrid.Converters"
                    xmlns:utilities="clr-namespace:Xceed.Wpf.Toolkit.Core.Utilities"
                    xmlns:commands="clr-namespace:Xceed.Wpf.Toolkit.PropertyGrid.Commands">

   <!-- =============================================================================== -->
   <!-- PropertyGrid                                                                    -->
   <!-- =============================================================================== -->

   <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
   <conv:InverseBoolConverter x:Key="InverseBoolConverter" />
   <pgconv:ExpandableObjectMarginConverter x:Key="ExpandableObjectMarginConverter" />
   <pgconv:ValueSourceToImagePathConverter x:Key="ValueSourceToImagePathConverter" />
   <pgconv:ValueSourceToToolTipConverter x:Key="ValueSourceToToolTipConverter" />

   <SolidColorBrush x:Key="MouseOverBorderBrush" Color="#FFFFB700" />
   <LinearGradientBrush x:Key="MouseOverBackgroundBrush" StartPoint="0,0" EndPoint="0,1">
      <GradientStop Offset="0" Color="#FFFEFBF4" />
      <GradientStop Offset="0.19" Color="#FFFDE7CE" />
      <GradientStop Offset="0.39" Color="#FFFDDEB8" />
      <GradientStop Offset="0.39" Color="#FFFFCE6B" />
      <GradientStop Offset="0.79" Color="#FFFFDE9A" />
      <GradientStop Offset="1" Color="#FFFFEBAA" />
   </LinearGradientBrush>

   <SolidColorBrush x:Key="CheckedBorderBrush" Color="#FFC29B29" />
   <LinearGradientBrush x:Key="CheckedBackgroundBrush" StartPoint="0,0" EndPoint="0,1">
      <GradientStop Offset="0" Color="#FFFFDCA0" />
      <GradientStop Offset="0.18" Color="#FFFFD692" />
      <GradientStop Offset="0.39" Color="#FFFFC45D" />
      <GradientStop Offset="1" Color="#FFFFD178" />
   </LinearGradientBrush>

   <SolidColorBrush x:Key="PressedBorderBrush" Color="#FFC29B29" />
   <LinearGradientBrush x:Key="PressedBackgroundBrush" StartPoint="0,0" EndPoint="0,1">
      <GradientStop Offset="0" Color="#FFE3C085" />
      <GradientStop Offset="0.19" Color="#FFF4CC89" />
      <GradientStop Offset="0.36" Color="#FFF5C777" />
      <GradientStop Offset="0.36" Color="#FFF5BB56" />
      <GradientStop Offset="0.79" Color="#FFF4CE9A" />
      <GradientStop Offset="1" Color="#FFF3E28D" />
   </LinearGradientBrush>

   <Style x:Key="OptionsToggleButtonStyle" TargetType="{x:Type RadioButton}">
      <Setter Property="Background" Value="Transparent" />
      <Setter Property="BorderBrush" Value="Transparent" />
      <Setter Property="BorderThickness" Value="1" />
      <Setter Property="FocusVisualStyle" Value="{x:Null}" />
      <Setter Property="Height" Value="22" />
      <Setter Property="HorizontalContentAlignment" Value="Center" />
      <Setter Property="ToolTipService.InitialShowDelay" Value="900" />
      <Setter Property="ToolTipService.ShowDuration" Value="20000" />
      <Setter Property="ToolTipService.BetweenShowDelay" Value="0" />
      <Setter Property="Template">
         <Setter.Value>
            <ControlTemplate TargetType="{x:Type RadioButton}">
               <Grid SnapsToDevicePixels="True">
                  <Border x:Name="OuterBorder" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" CornerRadius="2" />
                  <Border x:Name="MiddleBorder" BorderBrush="Transparent" BorderThickness="{TemplateBinding BorderThickness}" Background="Transparent" CornerRadius="2">
                     <Border x:Name="InnerBorder" BorderBrush="Transparent" BorderThickness="{TemplateBinding BorderThickness}" Background="Transparent" CornerRadius="2" Padding="{TemplateBinding Padding}">
                        <StackPanel x:Name="StackPanel" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}">
                           <ContentPresenter x:Name="Content"
                                             Content="{TemplateBinding Content}"
                                             Margin="1"
                                             RenderOptions.BitmapScalingMode="NearestNeighbor"
                                             VerticalAlignment="Center"
                                             HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" />
                        </StackPanel>
                     </Border>
                  </Border>
               </Grid>
               <ControlTemplate.Triggers>
                  <Trigger Property="IsMouseOver" Value="True">
                     <Setter Property="Background" TargetName="OuterBorder" Value="{StaticResource MouseOverBackgroundBrush}" />
                     <Setter Property="BorderBrush" TargetName="OuterBorder" Value="{StaticResource MouseOverBorderBrush}" />
                     <Setter Property="BorderBrush" TargetName="InnerBorder" Value="#80FFFFFF" />
                  </Trigger>

                  <Trigger Property="IsEnabled" Value="False">
                     <Setter Property="Opacity" TargetName="Content" Value="0.5" />
                     <Setter Property="TextElement.Foreground" TargetName="OuterBorder" Value="#FF9E9E9E" />
                  </Trigger>

                  <Trigger Property="IsChecked" Value="True">
                     <Setter Property="Background" TargetName="OuterBorder" Value="{StaticResource CheckedBackgroundBrush}" />
                     <Setter Property="BorderBrush" TargetName="OuterBorder" Value="{StaticResource CheckedBorderBrush}" />
                     <Setter Property="BorderBrush" TargetName="InnerBorder">
                        <Setter.Value>
                           <LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
                              <GradientStop Color="#FFE7CBAD" Offset="0" />
                              <GradientStop Color="#FFF7D7B5" Offset="0.1" />
                              <GradientStop Color="#FFFFD38C" Offset="0.36" />
                              <GradientStop Color="#FFFFC75A" Offset="0.36" />
                              <GradientStop Color="#FFFFEFA5" Offset="1" />
                           </LinearGradientBrush>
                        </Setter.Value>
                     </Setter>
                  </Trigger>

                  <Trigger Property="IsPressed" Value="True">
                     <Setter Property="Background" TargetName="OuterBorder" Value="{StaticResource PressedBackgroundBrush}" />
                     <Setter Property="BorderBrush" TargetName="OuterBorder" Value="{StaticResource PressedBorderBrush}" />
                     <Setter Property="BorderBrush" TargetName="InnerBorder" Value="Transparent" />
                  </Trigger>

                  <MultiTrigger>
                     <MultiTrigger.Conditions>
                        <Condition Property="IsChecked" Value="True" />
                        <Condition Property="IsMouseOver" Value="True" />
                     </MultiTrigger.Conditions>
                     <Setter Property="Background" TargetName="MiddleBorder">
                        <Setter.Value>
                           <LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
                              <GradientStop Color="#40FFFEFE" Offset="0" />
                              <GradientStop Color="#40FFFEFE" Offset="0.39" />
                              <GradientStop Color="#20FFCE68" Offset="0.39" />
                              <GradientStop Color="#20FFCE68" Offset="0.69" />
                              <GradientStop Color="#10FFFFFF" Offset="1" />
                           </LinearGradientBrush>
                        </Setter.Value>
                     </Setter>
                  </MultiTrigger>
               </ControlTemplate.Triggers>
            </ControlTemplate>
         </Setter.Value>
      </Setter>
   </Style>

   <Style x:Key="ClearFilterButtonStyle" TargetType="{x:Type Button}">
      <Setter Property="Background" Value="Transparent" />
      <Setter Property="BorderBrush" Value="Transparent" />
      <Setter Property="BorderThickness" Value="1" />
      <Setter Property="Height" Value="22" />
      <Setter Property="HorizontalContentAlignment" Value="Center" />
      <Setter Property="ToolTipService.InitialShowDelay" Value="900" />
      <Setter Property="ToolTipService.ShowDuration" Value="20000" />
      <Setter Property="ToolTipService.BetweenShowDelay" Value="0" />
      <Setter Property="Template">
         <Setter.Value>
            <ControlTemplate TargetType="{x:Type Button}">
               <Grid SnapsToDevicePixels="True">
                  <Border x:Name="OuterBorder" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" CornerRadius="2" />
                  <Border x:Name="MiddleBorder" BorderBrush="Transparent" BorderThickness="{TemplateBinding BorderThickness}" Background="Transparent" CornerRadius="2">
                     <Border x:Name="InnerBorder" BorderBrush="Transparent" BorderThickness="{TemplateBinding BorderThickness}" Background="Transparent" CornerRadius="2" Padding="{TemplateBinding Padding}">
                        <StackPanel x:Name="StackPanel" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}">
                           <ContentPresenter x:Name="Content"
                                             Content="{TemplateBinding Content}"
                                             Margin="1"
                                             RenderOptions.BitmapScalingMode="NearestNeighbor"
                                             VerticalAlignment="Center"
                                             HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" />
                        </StackPanel>
                     </Border>
                  </Border>
               </Grid>
               <ControlTemplate.Triggers>
                  <Trigger Property="IsMouseOver" Value="True">
                     <Setter Property="Background" TargetName="OuterBorder" Value="{StaticResource MouseOverBackgroundBrush}" />
                     <Setter Property="BorderBrush" TargetName="OuterBorder" Value="{StaticResource MouseOverBorderBrush}" />
                     <Setter Property="BorderBrush" TargetName="InnerBorder" Value="#80FFFFFF" />
                  </Trigger>

                  <Trigger Property="IsEnabled" Value="False">
                     <Setter Property="Opacity" TargetName="Content" Value="0.5" />
                     <Setter Property="TextElement.Foreground" TargetName="OuterBorder" Value="#FF9E9E9E" />
                  </Trigger>

                  <Trigger Property="IsPressed" Value="True">
                     <Setter Property="Background" TargetName="OuterBorder" Value="{StaticResource PressedBackgroundBrush}" />
                     <Setter Property="BorderBrush" TargetName="OuterBorder" Value="{StaticResource PressedBorderBrush}" />
                     <Setter Property="BorderBrush" TargetName="InnerBorder" Value="Transparent" />
                  </Trigger>
               </ControlTemplate.Triggers>
            </ControlTemplate>
         </Setter.Value>
      </Setter>
   </Style>

   <SolidColorBrush x:Key="GlyphBrush" Color="#FF31347C" />

   <ControlTemplate x:Key="ExpanderToggleButton" TargetType="{x:Type ToggleButton}">
      <Grid>
         <Rectangle Margin="0,0,0,0" x:Name="Rectangle" Fill="Transparent" />
         <Path HorizontalAlignment="Center" x:Name="Up_Arrow" VerticalAlignment="Center" Fill="{StaticResource GlyphBrush}" Data="M 0 0 L 4 4 L 8 0 Z" RenderTransformOrigin="0.5,0.5">
            <Path.RenderTransform>
               <TransformGroup>
                  <ScaleTransform ScaleX="1" ScaleY="1" />
                  <SkewTransform AngleX="0" AngleY="0" />
                  <RotateTransform Angle="-90" />
                  <TranslateTransform X="0" Y="0" />
               </TransformGroup>
            </Path.RenderTransform>
         </Path>
         <Path Visibility="Collapsed" HorizontalAlignment="Center" x:Name="Down_Arrow" VerticalAlignment="Center" Fill="{StaticResource GlyphBrush}" Data="M 0 4 L 4 0 L 8 4 Z" RenderTransformOrigin="0.5,0.5">
            <Path.RenderTransform>
               <TransformGroup>
                  <ScaleTransform ScaleX="1" ScaleY="1" />
                  <SkewTransform AngleX="0" AngleY="0" />
                  <RotateTransform Angle="135" />
                  <TranslateTransform X="0" Y="0" />
               </TransformGroup>
            </Path.RenderTransform>
         </Path>
      </Grid>
      <ControlTemplate.Triggers>
         <Trigger Property="IsChecked" Value="true">
            <Setter Property="Visibility" Value="Visible" TargetName="Down_Arrow" />
            <Setter Property="Visibility" Value="Collapsed" TargetName="Up_Arrow" />
            <Setter Property="OpacityMask" TargetName="Down_Arrow" Value="#FF000000" />
         </Trigger>
      </ControlTemplate.Triggers>
   </ControlTemplate>

   <Style x:Key="ExpanderStyle" TargetType="{x:Type Expander}">
      <Setter Property="Padding" Value="0" />
      <Setter Property="Background" Value="#FFF0F0F0" />
      <Setter Property="Template">
         <Setter.Value>
            <ControlTemplate TargetType="{x:Type Expander}">
               <Grid>
                  <Grid.RowDefinitions>
                     <RowDefinition Height="Auto" />
                     <RowDefinition Height="*" x:Name="ContentRow" />
                  </Grid.RowDefinitions>
                  <Border x:Name="Border" Background="{TemplateBinding Background}" BorderBrush="#FFF0F0F0">
                     <Grid>
                        <Grid.ColumnDefinitions>
                           <ColumnDefinition Width="20" />
                           <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                        <ToggleButton Template="{StaticResource ExpanderToggleButton}" IsChecked="{Binding Path=IsExpanded, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" OverridesDefaultStyle="True" />
                        <ContentPresenter Grid.Column="1" Margin="1" RecognizesAccessKey="True" ContentSource="Header" TextElement.FontWeight="Bold" />
                     </Grid>
                  </Border>
                  <Border Visibility="Collapsed" Grid.Row="1" x:Name="ExpandSite" Background="#FFF0F0F0" Padding="10 0 0 0">
                     <Border Background="#FFFFFF" BorderThickness="0" Margin="0" Padding="0" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
                        <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Focusable="false" />
                     </Border>
                  </Border>
               </Grid>
               <ControlTemplate.Triggers>
                  <Trigger Property="IsExpanded" Value="True">
                     <Setter Property="Visibility" Value="Visible" TargetName="ExpandSite" />
                  </Trigger>
               </ControlTemplate.Triggers>
            </ControlTemplate>
         </Setter.Value>
      </Setter>
   </Style>

   <Style x:Key="PropertyExpanderStyle" TargetType="{x:Type Expander}">
      <Setter Property="Padding" Value="10 0 0 0" />
      <Setter Property="Template">
         <Setter.Value>
            <ControlTemplate TargetType="{x:Type Expander}">
               <Grid>
                  <Border Visibility="Collapsed" Grid.Row="1" x:Name="ExpandSite" Padding="0 0 0 0">
                     <Border BorderThickness="0" Margin="0" Padding="0" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
                        <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
												      VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
												      Focusable="false" />
                     </Border>
                  </Border>
               </Grid>
               <ControlTemplate.Triggers>
                  <Trigger Property="IsExpanded" Value="True">
                     <Setter Property="Visibility" Value="Visible" TargetName="ExpandSite" />
                  </Trigger>
               </ControlTemplate.Triggers>
            </ControlTemplate>
         </Setter.Value>
      </Setter>
   </Style>

   <ContextMenu x:Key="DefaultAdvancedOptionsMenu">
      <MenuItem Header="Reset Value" Command="commands:PropertyItemCommands.ResetValue" />
   </ContextMenu>

   <Style TargetType="{x:Type pg:PropertyItem}">
      <Setter Property="BorderBrush" Value="#FFF0F0F0" />
      <Setter Property="BorderThickness" Value="1" />
      <Setter Property="Focusable" Value="True" />
      <Setter Property="IsTabStop" Value="False" />
      <Setter Property="Template">
         <Setter.Value>
            <ControlTemplate TargetType="{x:Type pg:PropertyItem}">
               <Border Background="White" ContextMenu="{Binding AdvancedOptionsMenu, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=pg:PropertyGrid}}" ContextMenuService.Placement="Bottom">
                  <Grid VerticalAlignment="Center" HorizontalAlignment="Stretch">
                     <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="{Binding NameColumnWidth, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type pg:PropertyGrid}}}" />
                        <ColumnDefinition Width="*" />
                     </Grid.ColumnDefinitions>
                     <Grid.RowDefinitions>
                        <RowDefinition />
                        <RowDefinition />
                     </Grid.RowDefinitions>

                     <Border BorderThickness="0.5" BorderBrush="#FFF0F0F0" x:Name="PART_Name">
                        <Grid Margin="2,2,2,2">
                           <Grid.ColumnDefinitions>
                              <ColumnDefinition Width="*" />
                              <ColumnDefinition Width="Auto" />
                           </Grid.ColumnDefinitions>

                           <Grid Margin="{Binding Level, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource ExpandableObjectMarginConverter}}">
                              <Grid.ColumnDefinitions>
                                 <ColumnDefinition Width="15" />
                                 <ColumnDefinition Width="*" />
                              </Grid.ColumnDefinitions>

                              <Border Grid.Column="0">
                                 <ToggleButton Template="{StaticResource ExpanderToggleButton}"
                                               OverridesDefaultStyle="True"
                                               IsChecked="{Binding IsExpanded, RelativeSource={RelativeSource TemplatedParent}}"
                                               Visibility="{Binding HasChildProperties, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource BooleanToVisibilityConverter}}" />
                              </Border>

                              <TextBlock Grid.Column="1" Text="{Binding DisplayName, RelativeSource={RelativeSource TemplatedParent}}" HorizontalAlignment="Stretch" TextTrimming="CharacterEllipsis" />
                           </Grid>

                           <Grid Grid.Column="1"
                                 HorizontalAlignment="Right"
                                 Margin="5,0,5,0"
                                 Visibility="{Binding ShowAdvancedOptions, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=pg:PropertyGrid}, Converter={StaticResource BooleanToVisibilityConverter}}"
                                 utilities:ContextMenuUtilities.OpenOnMouseLeftButtonClick="True"
                                 ContextMenu="{Binding AdvancedOptionsMenu, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=pg:PropertyGrid}}">

                              <Image x:Name="_optionsImage"
                                     Width="11"
                                     Height="11"
                                     Source="{Binding ValueSource, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource ValueSourceToImagePathConverter}}"
                                     ToolTip="{Binding ValueSource, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource ValueSourceToToolTipConverter}}" />
                           </Grid>
                        </Grid>
                     </Border>

                     <Border BorderThickness="0.5" BorderBrush="#FFF0F0F0" x:Name="PART_Editor" Grid.Column="1" Background="Transparent">
                        <ContentControl Content="{TemplateBinding Editor}" VerticalAlignment="Center" Focusable="False" IsTabStop="False" />
                     </Border>

                     <Expander x:Name="_propertyExpander" Grid.ColumnSpan="2" Grid.Row="1" IsExpanded="{TemplateBinding IsExpanded}" Style="{StaticResource PropertyExpanderStyle}" IsEnabled="True">
                        <ItemsControl ItemsSource="{Binding Properties, RelativeSource={RelativeSource TemplatedParent}}" IsTabStop="False" Focusable="False">
                           <ItemsControl.ItemsPanel>
                              <ItemsPanelTemplate>
                                 <VirtualizingStackPanel />
                              </ItemsPanelTemplate>
                           </ItemsControl.ItemsPanel>
                        </ItemsControl>
                     </Expander>
                  </Grid>
               </Border>
               <ControlTemplate.Triggers>
                  <DataTrigger Binding="{Binding IsDataBound, RelativeSource={RelativeSource Self}}" Value="True">
                     <Setter TargetName="_optionsImage" Property="Source" Value="/WPFToolkit.Extended;component/PropertyGrid/Images/Database11.png" />
                     <Setter TargetName="_optionsImage" Property="ToolTip" Value="Databinding" />
                  </DataTrigger>
                  <DataTrigger Binding="{Binding IsDynamicResource, RelativeSource={RelativeSource Self}}" Value="True">
                     <Setter TargetName="_optionsImage" Property="Source" Value="/WPFToolkit.Extended;component/PropertyGrid/Images/Resource11.png" />
                     <Setter TargetName="_optionsImage" Property="ToolTip" Value="Resource" />
                  </DataTrigger>
                  <DataTrigger Binding="{Binding HasResourceApplied, RelativeSource={RelativeSource Self}}" Value="True">
                     <Setter TargetName="_optionsImage" Property="Source" Value="/WPFToolkit.Extended;component/PropertyGrid/Images/Resource11.png" />
                     <Setter TargetName="_optionsImage" Property="ToolTip" Value="Resource" />
                  </DataTrigger>
                  <Trigger Property="IsMouseOver" Value="True">
                     <Setter TargetName="PART_Name" Property="Background" Value="#CED4DF" />
                  </Trigger>
                  <Trigger Property="IsSelected" Value="True">
                     <Setter TargetName="PART_Name" Property="Background" Value="#43577B" />
                     <Setter TargetName="PART_Name" Property="TextElement.Foreground" Value="White" />
                  </Trigger>
               </ControlTemplate.Triggers>
            </ControlTemplate>
         </Setter.Value>
      </Setter>
   </Style>

   <Style TargetType="{x:Type pg:PropertyGrid}">
      <Setter Property="AdvancedOptionsMenu" Value="{StaticResource DefaultAdvancedOptionsMenu}" />
      <Setter Property="Background" Value="#CED4DF" />
      <Setter Property="BorderBrush" Value="#43577B" />
      <Setter Property="BorderThickness" Value="1" />
      <Setter Property="Template">
         <Setter.Value>
            <ControlTemplate TargetType="{x:Type pg:PropertyGrid}">
               <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
                  <Grid>
                     <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto" />
                        <RowDefinition />
                        <RowDefinition Height="5" />
                        <RowDefinition Height="Auto"/>
                     </Grid.RowDefinitions>

                     <StackPanel Orientation="Horizontal" Margin="6,2,0,4">
                        <TextBlock Text="{TemplateBinding SelectedObjectTypeName}" FontWeight="Bold" />
                        <TextBlock Text="{TemplateBinding SelectedObjectName}" Margin="5,0,0,0" />
                     </StackPanel>

                     <Grid Grid.Row="1" Margin="4,0,4,4">
                        <Grid.ColumnDefinitions>
                           <ColumnDefinition Width="Auto" />
                           <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                        <Grid Background="#BCC7D8" Margin="4" Visibility="{Binding ShowSortOptions, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource BooleanToVisibilityConverter}}">
                           <StackPanel Orientation="Horizontal" Margin="1" >
                              <RadioButton IsChecked="{Binding IsCategorized, RelativeSource={RelativeSource TemplatedParent}}"
                                           VerticalAlignment="Center"
                                           Style="{StaticResource OptionsToggleButtonStyle}"
                                           ToolTip="Categorized">
                                 <Image Source="/WPFToolkit.Extended;component/PropertyGrid/Images/Categorize16.png" Width="16" Height="16" />
                              </RadioButton>
                              <RadioButton IsChecked="{Binding IsCategorized, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource InverseBoolConverter}, Mode=OneWay}"
                                           VerticalAlignment="Center"
                                           Style="{StaticResource OptionsToggleButtonStyle}"
                                           ToolTip="Alphabetical">
                                 <Image Source="/WPFToolkit.Extended;component/PropertyGrid/Images/SortAscending16.png" Width="16" Height="16" />
                              </RadioButton>
                           </StackPanel>
                        </Grid>

                        <Border Grid.Column="1" Margin="4,4,0,4" Background="White" BorderBrush="Gray" BorderThickness="1" Visibility="{Binding ShowSearchBox, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource BooleanToVisibilityConverter}}">
                           <Grid>
                              <Grid.ColumnDefinitions>
                                 <ColumnDefinition Width="*" />
                                 <ColumnDefinition Width="Auto" />
                              </Grid.ColumnDefinitions>
                              <local:WatermarkTextBox x:Name="_txtFilter"
                                                      Background="Transparent" 
                                                      Text="{Binding Filter, RelativeSource={RelativeSource TemplatedParent}, UpdateSourceTrigger=PropertyChanged}"
                                                      Watermark="{TemplateBinding FilterWatermark}">
                                 <local:WatermarkTextBox.Style>
                                    <Style TargetType="Control">
                                       <Setter Property="BorderThickness" Value="0" />
                                       <Style.Triggers>
                                          <Trigger Property="IsMouseOver" Value="True">
                                             <Setter Property="BorderThickness" Value="1" />
                                          </Trigger>
                                       </Style.Triggers>
                                    </Style>
                                 </local:WatermarkTextBox.Style>

                              </local:WatermarkTextBox>

                              <Button Grid.Column="1"
                                      Command="commands:PropertyGridCommands.ClearFilter"
                                      Style="{StaticResource ClearFilterButtonStyle}"
                                      HorizontalAlignment="Left">
                                 <Image Source="/WPFToolkit.Extended;component/PropertyGrid/Images/ClearFilter16.png" Width="16" Height="16" />
                              </Button>
                           </Grid>
                        </Border>
                     </Grid>

                     <Grid Grid.Row="2" Background="White">
                        <ScrollViewer VerticalScrollBarVisibility="Auto">
                           <ItemsControl ItemsSource="{Binding Properties, RelativeSource={RelativeSource TemplatedParent}}" IsTabStop="False" Focusable="False">
                              <ItemsControl.ItemsPanel>
                                 <ItemsPanelTemplate>
                                    <VirtualizingStackPanel />
                                 </ItemsPanelTemplate>
                              </ItemsControl.ItemsPanel>

                              <ItemsControl.GroupStyle>
                                 <GroupStyle>
                                    <GroupStyle.ContainerStyle>
                                       <Style TargetType="{x:Type GroupItem}">
                                          <Setter Property="Template">
                                             <Setter.Value>
                                                <ControlTemplate>
                                                   <Border Background="{TemplateBinding Background}"
                                                           BorderBrush="{TemplateBinding BorderBrush}"
                                                           BorderThickness="{TemplateBinding BorderThickness}">
                                                      <Expander Header="{Binding Name}" Style="{StaticResource ExpanderStyle}" IsExpanded="True">
                                                         <ItemsPresenter />
                                                      </Expander>
                                                   </Border>
                                                </ControlTemplate>
                                             </Setter.Value>
                                          </Setter>
                                       </Style>
                                    </GroupStyle.ContainerStyle>
                                 </GroupStyle>
                              </ItemsControl.GroupStyle>

                           </ItemsControl>
                        </ScrollViewer>

                        <Thumb x:Name="PART_DragThumb" HorizontalAlignment="Left" Width="5" Margin="6,0,0,0" Cursor="SizeWE">
                           <Thumb.RenderTransform>
                              <TranslateTransform X="{Binding NameColumnWidth, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type pg:PropertyGrid}}}" />
                           </Thumb.RenderTransform>
                           <Thumb.Template>
                              <ControlTemplate>
                                 <Border Background="Transparent" />
                              </ControlTemplate>
                           </Thumb.Template>
                        </Thumb>

                     </Grid>

                     <GridSplitter Height="3" Grid.Row="3" HorizontalAlignment="Stretch" Visibility="{Binding DisplaySummary, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource BooleanToVisibilityConverter}}" />
                     <StackPanel Grid.Row="4" Margin="0,0,0,5" Visibility="{Binding DisplaySummary, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource BooleanToVisibilityConverter}}">
                        <TextBlock Padding="2 2 2 0" FontWeight="Bold" Text="{Binding SelectedProperty.DisplayName, RelativeSource={RelativeSource TemplatedParent}}" />
                        <TextBlock Padding="5 2 2 0" TextWrapping="WrapWithOverflow" Text="{Binding SelectedProperty.Description, RelativeSource={RelativeSource TemplatedParent}}" />
                     </StackPanel>
                  </Grid>
               </Border>
            </ControlTemplate>
         </Setter.Value>
      </Setter>
   </Style>

</ResourceDictionary>